﻿using System;
using System.Data;

namespace TurtleEngine
{
	 /// <summary>
	 ///
	 /// </summary>
	 public class InstanceInformationHelper
	 {
		  /// <summary>
		  /// The instance information
		  /// </summary>
		  private static readonly DataTable instanceInformation = new DataTable("InstanceInformation");

		  /// <summary>
		  /// Gets the instance information.
		  /// </summary>
		  /// <value>
		  /// The instance information.
		  /// </value>
		  public static DataTable InstanceInformation
		  {
				get { return instanceInformation; }
		  }

		  /// <summary>
		  /// Gets the instance information.
		  /// </summary>
		  public static void GetInstanceInformation()
		  {
				String dataSource = Utility.DBConnection.DataSource;
				Int32 packetSize = Utility.DBConnection.PacketSize;
				String serverVersion = Utility.DBConnection.ServerVersion;
				Boolean statisticsEnabled = Utility.DBConnection.StatisticsEnabled;
				String workstationId = Utility.DBConnection.WorkstationId;

				CreateInstanceInformationSchema();
				instanceInformation.Rows.Add(dataSource, packetSize, serverVersion, statisticsEnabled, workstationId);

				//Utility.PrintDatatable(instanceInformation);
		  }

		  /// <summary>
		  /// Writes the instance information.
		  /// </summary>
		  public static void WriteInstanceInformation()
		  {
				string xmlfile = instanceInformation.TableName + ".xml";
				string xslFile = instanceInformation.TableName + ".xsl";
				string htmFile = instanceInformation.TableName + ".htm";

				Utility.WriteXML(instanceInformation, xmlfile);
				Utility.WriteHTML(xmlfile, xslFile, htmFile);
		  }

		  /// <summary>
		  /// Creates the instance information schema.
		  /// </summary>
		  private static void CreateInstanceInformationSchema()
		  {
				instanceInformation.Columns.Clear();

				instanceInformation.Columns.Add("dataSource", typeof(String));
				instanceInformation.Columns.Add("packetSize", typeof(String));
				instanceInformation.Columns.Add("serverVersion", typeof(String));
				instanceInformation.Columns.Add("statisticsEnabled", typeof(String));
				instanceInformation.Columns.Add("workstationId", typeof(String));
		  }
	 }
}